{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# INVALID_CONCURRENT_GRAPH_UPDATE\n",
    "\n",
    "A LangGraph [`StateGraph`](https://langchain-ai.github.io/langgraphjs/reference/classes/langgraph.StateGraph.html) received concurrent updates to its state from multiple nodes to a state property that doesn't\n",
    "support it.\n",
    "\n",
    "One way this can occur is if you are using a [fanout](https://langchain-ai.github.io/langgraphjs/how-tos/map-reduce/)\n",
    "or other parallel execution in your graph and you have defined a state with a value like this:\n",
    "\n",
    "```ts\n",
    "const StateAnnotation = Annotation.Root({\n",
    "  someKey: Annotation<string>,\n",
    "});\n",
    "\n",
    "const graph = new StateGraph(StateAnnotation)\n",
    "  .addNode(...)\n",
    "  ...\n",
    "  .compile();\n",
    "```\n",
    "\n",
    "If a node in the above graph returns `{ someKey: \"someStringValue\" }`, this will overwrite the state value for `someKey` with `\"someStringValue\"`.\n",
    "However, if multiple nodes in e.g. a fanout within a single step return values for `\"someKey\"`, the graph will throw this error because\n",
    "there is uncertainty around how to update the internal state.\n",
    "\n",
    "To get around this, you can define a reducer that combines multiple values:\n",
    "\n",
    "```ts\n",
    "const StateAnnotation = Annotation.Root({\n",
    "  someKey: Annotation<string[]>({\n",
    "    default: () => [],\n",
    "    reducer: (a, b) => a.concat(b),\n",
    "  }),\n",
    "});\n",
    "```\n",
    "\n",
    "This will allow you to define logic that handles the same key returned from multiple nodes executed in parallel.\n",
    "\n",
    "## Troubleshooting\n",
    "\n",
    "The following may help resolve this error:\n",
    "\n",
    "- If your graph executes nodes in parallel, make sure you have defined relevant state keys with a reducer.\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
